﻿using System;
using System.Collections.Generic;

namespace smp.ButterflyCakes.Models.ViewModels.Schedule
{
    public class ScheduleCalendarItem
    {
        public ScheduleCalendarItem(DateTime date, bool isCalendarTargetMonth, List<ScheduleListItem> scheduleItems)
        {
            Date = date;
            IsCalendarTargetMonth = isCalendarTargetMonth;
            Confirmed = scheduleItems.FindAll(x => x.IsConfirmed).Count;
            Enquiries = scheduleItems.FindAll(x => !x.IsConfirmed).Count;
            Cancelled = scheduleItems.FindAll(x => x.OrderStatus == Status.Cancelled).Count;
            if(scheduleItems.Count > 0)
            {
                ToolTipText = "<ul>";
            }
            for (int index = 0; index < scheduleItems.Count; index++)
            {
                var item = scheduleItems[index];
                if(item.IsConfirmed)
                {
                    ToolTipText +=
                        string.Format(
                            "<li><i class=\"icon-ok\"/><p class=\"text-success\" style=\"font-size:12px;\">{0}</p></li>",
                            item.Description);
                }
                else
                {
                    ToolTipText +=
                        string.Format(
                            "<li><i class=\"icon-question-sign\"/><p class=\"text-warning\" style=\"font-size:12px;\">{0}</p></li>",
                            item.Description);
                }
                //ToolTipText += string.Format("<div class=\"row\">{0}. {1} {2}</div>", i+1, scheduleItems[i].Description,
                //                                 scheduleItems[i].IsConfirmed ? " - Confirmed" : "");
            }
            if (scheduleItems.Count > 0)
            {
                ToolTipText += "</ul>";
            }
        }

        public int Day { get { return Date.Day; } }

        public bool IsCalendarTargetMonth { get; private set; }

        public DateTime Date { get; private set; }

        public int Confirmed { get; private set; }

        public int Enquiries { get; private set; }

        public string EnquiriesText
        {
            get
            {
                if (Enquiries == 0)
                    return "";
                if (Enquiries == 1)
                    return Enquiries + " Enquiry";
                return Enquiries + " Enquiries";
            }
        }

        public int Cancelled { get; private set; }

        public string OutOfMonthClassName
        {
            get
            {
                return !IsCalendarTargetMonth ? "calendarBoxGreyedOut" : "";
            }
        }

        public string ToolTipTitle
        {
            get { return Date.ToString("dd-MMMM-yyyy"); }
        }

        public string ToolTipText { get; set; }
    }
}
